<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateResultsDataTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        /***
         * 录取专业
         */
        Schema::create('result_majors', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('exam_code')->unique()->comment('学生考试号');
            $table->string('code')->comment('录取专业代码');
            $table->string('name')->comment('录取专业名称');
            $table->integer('count')->comment('填报志愿数');
            $table->string('detail')->comment('志愿详情');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('exam_code')->references('exam_code')->on('basic_new_students')
                ->onDelete('restrict')->onUpdate('cascade');

            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });


        /***
         * 分配班级
         */
        Schema::create('result_classes', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('exam_code')->unique()->comment('学生考试号');
            $table->string('code')->comment('班级代码');
            $table->string('name')->comment('班级名称');
            $table->string('headteacher')->comment('班主任');
            $table->string('counselor')->nullable()->comment('辅导员');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('exam_code')->references('exam_code')->on('basic_new_students')
                ->onDelete('restrict')->onUpdate('cascade');

            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });

        /***
         * 分配宿舍
         */
        Schema::create('result_dorms', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('exam_code')->unique()->comment('学生考试号');
            $table->string('dorm_code')->comment('宿舍号');
            $table->string('bed_number')->comment('床位号');
            $table->string('building')->comment('楼栋');
            $table->string('floor')->comment('楼层');
            $table->boolean('is_manager')->default(false)->comment('是否为舍长');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('exam_code')->references('exam_code')->on('basic_new_students')
                ->onDelete('restrict')->onUpdate('cascade');

            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });

        /***
         * 学生最终选择的校服
         */
        Schema::create('result_clothes', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('exam_code')->comment('学生考试号');
            $table->string('cloth_code')->comment('校服代码');
            $table->string('size_code')->comment('尺寸代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('exam_code')->references('exam_code')->on('basic_new_students')
                ->onDelete('restrict')->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('result_majors');
        Schema::dropIfExists('result_classes');
        Schema::dropIfExists('result_dorms');
    }
}
